package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.StatusEvent;
	/**
	 * ...
	 * @author ElviS
	 */
	public class Main extends Sprite
	{
		//объявляем игровые экраны.
		private var _currentScreen:GameScreen;
		private var gameMenu:GameMenu;
		private var ballsGame:BallsGame;
		private var gameInfo:GameInfo;
		
		public function Main() 
		{
			gameMenu = new GameMenu();
			ballsGame = new BallsGame();
			gameInfo = new GameInfo();
			
			_currentScreen = gameMenu;
			
			_currentScreen.addEventListener(StatusEvent.STATUS, gameStatus);
			
			addChild(_currentScreen);
		}
		
		private function gameStatus(e:StatusEvent):void 
		{
			switch (e.level)
			{
				case "gotoMenu":
					changeScreen(gameMenu);
				break;
				
				case "gotoGame":
					changeScreen(ballsGame);
				break;
				
				case "gotoGameInfo":
					gameInfo.time = e.code;
					changeScreen(gameInfo);
				break;
			}
		}
		
		//тут происходит смена экранов
		public function changeScreen(screen:GameScreen)
		{
			_currentScreen.stop();
			_currentScreen.removeEventListener(StatusEvent.STATUS, gameStatus);
			removeChild(_currentScreen);
			
			_currentScreen = screen;
			addChild(_currentScreen);
			_currentScreen.addEventListener(StatusEvent.STATUS, gameStatus);
			_currentScreen.start();
		}
		
		public function onGame(e:Event):void
		{
			
		}
		
	}

}